package cn.itcast.user.web;

import cn.itcast.user.config.PatternProperties;
import cn.itcast.user.pojo.User;
import cn.itcast.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.regex.Pattern;

@Slf4j
@RestController
@RequestMapping("/user")
// @RefreshScope  //为非爱斯 斯搞破 刷新范围
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 路径： /user/110
     *
     * @param id 用户id
     * @return 用户
     */
    @GetMapping("/{id}")
    public User queryById(@PathVariable("id") Long id) {
        return userService.queryById(id);
    }
//   @Value("${pattern.dateformat}")   //pattern 怕得 模式
//    private  String  dateformat;
  @Autowired
    PatternProperties patternProperties;
         @GetMapping("prop")
    public PatternProperties getPatternProperties() {
        return patternProperties;
    }
    //    @GetMapping("now")
//    public String now(){
//        return LocalDateTime.now().format(DateTimeFormatter.ofPattern(patternProperties.getDateformat()));
//    }
//    @GetMapping("/{id}")
//    public User queryById(@PathVariable("id") Long id,
//                          @RequestHeader(value = "Truth",required = false) String name) {
//        System.out.println("请求头中携带的name = " + name);
//        return userService.queryById(id);
//    }

}
